<?php

namespace app\common\model;

use think\Model;

class UserAttribute extends Model
{
    // 表名
    protected $name = 'user_attribute';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;

    // 追加属性
    protected $append = [
        'cash_status_text',
        'single_status_text',
        'real_auth_status_text',
        'task_status_text',
        'group_time_text',
        'account_status_text'
    ];



    public function getCashStatusList()
    {
        return ['1' => __('Cash_status 1'),'2' => __('Cash_status 2')];
    }

    public function getSingleStatusList()
    {
        return ['1' => __('Single_status 1'),'2' => __('Single_status 2')];
    }

    public function getRealAuthStatusList()
    {
        return ['1' => __('Real_auth_status 1'),'2' => __('Real_auth_status 2')];
    }

    public function getTaskStatusList()
    {
        return ['1' => __('Task_status 1'),'2' => __('Task_status 2')];
    }

    public function getAccountStatusList()
    {
        return ['1' => __('Account_status 1'),'2' => __('Account_status 2')];
    }


    public function getCashStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cash_status']) ? $data['cash_status'] : '');
        $list = $this->getCashStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSingleStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['single_status']) ? $data['single_status'] : '');
        $list = $this->getSingleStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRealAuthStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['real_auth_status']) ? $data['real_auth_status'] : '');
        $list = $this->getRealAuthStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTaskStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['task_status']) ? $data['task_status'] : '');
        $list = $this->getTaskStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGroupTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['group_time']) ? $data['group_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAccountStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['account_status']) ? $data['account_status'] : '');
        $list = $this->getAccountStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setGroupTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
